/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Fri.DAOLayer;

import fri.businessLayer.UserBeanRemote;
import fri.entiry.FrUser;
import java.util.List;
import java.util.Vector;
import javax.naming.Context;
import javax.naming.InitialContext;

/**
 *
 * @author NguyenDongUIT
 */
public class UserDAO {
    
    public static FrUser searchUserByCode(String userCode) {
        try {

            Context ic = new InitialContext();
            UserBeanRemote rm = (UserBeanRemote) ic.lookup("fri.businessLayer.UserBeanRemote");
            return rm.getUserByCode(userCode);

        } catch (Exception e) {

            e.printStackTrace();
            System.out.println("Error when get user code: " + e.getMessage());
        }
        return null;
    }
    public static List<FrUser> getAllUser() {
        try {

            Context ic = new InitialContext();
            UserBeanRemote rm = (UserBeanRemote) ic.lookup("fri.businessLayer.UserBeanRemote");
            return rm.getAllUser();

        } catch (Exception e) {

            e.printStackTrace();
            System.out.println("Error when get user code: " + e.getMessage());
        }
        return null;
    }
    
    public static FrUser searchUserByUserId(String userId) {
        try {

            Context ic = new InitialContext();
            UserBeanRemote rm = (UserBeanRemote) ic.lookup("fri.businessLayer.UserBeanRemote");
            return rm.getUserByUserId(userId);

        } catch (Exception e) {

            e.printStackTrace();
            System.out.println("Error when get user code: " + e.getMessage());
        }
        return null;
    }
    
    public static boolean checkLogin(FrUser user) {
        try {

            Context ic = new InitialContext();
            UserBeanRemote rm = (UserBeanRemote) ic.lookup("fri.businessLayer.UserBeanRemote");
            return rm.checkLogin(user);

        } catch (Exception e) {

            e.printStackTrace();
            System.out.println("Error when get user code: " + e.getMessage());
        }
        return false;
    }
    
}
